home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / HyperCard Dev. ToolKit / Serial & MacinTalk XCMDs / bufferSPort.p next >
Text File  |  1987-07-15  |  2KB  |  88 lines

  1. {$R-}
  2.  
  3. (*
  4.     bufferSPort(port number, oldBuffer,sizeOfBuffer) -- Free the old buffer at the address specified by
  5.     oldBuffer (if non-zero), and allocate a new buffer of sizeOfBuffer (or revert to default buffer if
  6.     zero). Return the address of the allocated buffer or zero if sizeOfBuffer is zero.
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     pascal -w bufferSPort.p
  11.     link -m ENTRYPOINT -o HyperCommands -rt XFCN=3 -sn Main=bufferSPort bufferSPort.p.o "{MPW}"Libraries:interface.o
  12.     
  13. *)
  14.  
  15. {$S bufferSPort }     { Segment name must be the same as the command name. }
  16.  
  17. unit DummyUnit;
  18.  
  19. interface
  20.  
  21. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  22.  
  23. procedure EntryPoint(paramPtr: XCmdPtr);
  24.     
  25. implementation
  26.  
  27. const
  28.  
  29. return = chr(13);
  30. linefeed = chr(10);
  31. bs = chr(8);
  32.  
  33. type
  34.  
  35. Str31 = String[31];
  36.  
  37. procedure bufferSPort(paramPtr: XCmdPtr); forward;
  38.  
  39. procedure EntryPoint(paramPtr: XCmdPtr);
  40.  
  41.     begin
  42.         bufferSPort(paramPtr);
  43.     end;
  44.  
  45. procedure bufferSPort(paramPtr: XCmdPtr);
  46.  
  47.     var portNumber: integer;
  48.         oldBufferPtr: Ptr;
  49.         newBufferPtr: Ptr;
  50.         newBufferSize: longInt;
  51.         inPort, outPort: integer;
  52.         str: Str255;
  53.  
  54.     {$I XCmdGlue.inc}
  55.  
  56.     procedure Fail(errMsg: Str255); { set theResult and quit }
  57.         begin
  58.             paramPtr^.returnValue := PasToZero(errMsg);
  59.             exit(bufferSPort);
  60.         end;
  61.  
  62.     begin
  63.         if paramPtr^.paramCount <> 3 then Fail('parameter count is not 3');
  64.  
  65.         ZeroToPas(paramPtr^.params[1]^,str);        { First parameter is port number. }
  66.         portNumber := StrToNum(str);
  67.         if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
  68.         ZeroToPas(paramPtr^.params[2]^,str);        { Second parameter is old buffer address. }
  69.         oldBufferPtr := Ptr(StrToNum(str));
  70.         ZeroToPas(paramPtr^.params[3]^,str);        { Third parameter is new buffer size. }
  71.         newBufferSize := StrToNum(str);
  72.  
  73.         if portNumber = 1 then inPort := -6
  74.         else inPort := -8;
  75.  
  76.         if newBufferSize = 0 then newBufferPtr := nil
  77.         else newBufferPtr := NewPtr(newBufferSize);
  78.         if SerSetBuf(inPort,newBufferPtr,newBufferSize) <> noErr then
  79.             begin
  80.                 DisposPtr(newBufferPtr);
  81.                 Fail('SetSetBuf failed');
  82.             end;
  83.         if oldBufferPtr <> NIL then DisposPtr(oldBufferPtr);
  84.         str := LongToStr(ord4(newBufferPtr));
  85.         paramPtr^.returnValue := PasToZero(str);
  86.     end;
  87. end.
  88.